<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>心理训练方案</title>
    <script type="text/javascript" src="../../framework/jquery-1.11.3.min.js"></script>
    <script type="text/javascript" src="../../js/login_common.js"></script>
    <script type="text/javascript" src="../../layui/layui.js"></script>
    <link rel="stylesheet" href="../../layui/css/layui.css">
    <script src="../../layui/extend/treeGrid.js"></script>
</head>
<body>
<div class="demoTable">
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>

<script type="text/html" id="toolbarDemo">
    <div class="layui-inline">
        <input class="layui-input"id="schemeName" name="schemeName"  autocomplete="off" placeholder="请输入方案名称">
    </div>
    <div class="layui-input-inline">
        <input type="text" class="layui-input" id="stime" name="stime" placeholder="请输入开始日期" >
    </div>
    <div class="layui-input-inline">
        <input type="text" class="layui-input" id="etime" name="etime"  placeholder="请输入结束日期" >
    </div>
    <button class="layui-btn" data-type="reload" lay-event="findByKey" id="findByKey">搜索</button>
    {{# if(hasPrivilege("ATSSCHEME_ACTION")){ }}
    <button class="layui-btn" id="delMany" lay-event="delMany"  data-type="reload">批量删除</button>
    <button class="layui-btn" id="add" lay-event="add"  data-type="reload">增加</button>
    {{# } }}
    {{# if(hasPrivilege("LOOK_ALL_SELF")){ }}
    <button class="layui-btn" id="findAllScheme" lay-event="findAllScheme"  data-type="reload">查看所有</button>
    <button class="layui-btn" id="onlyLookSelf" lay-event="onlyLookSelf"  data-type="reload">只看自己</button>
    {{# } }}
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-bg-blue layui-btn-xs" lay-event="look" id="look">查看</a>
    {{# if(hasPrivilege("ATSSCHEME_AUDIT")){ }}
    <a class="layui-btn layui-btn-danger  layui-btn-xs" lay-event="audit" id="audit">审核</a>
    {{# } }}
    {{# if(hasPrivilege("ATSSCHEME_REPLY")){ }}
    <a class="layui-btn layui-bg-orange  layui-btn-xs" lay-event="reply" id="reply">回复</a>
    {{# } }}
    {{# if(hasPrivilege("ATSSCHEME_ACTION")){ }}
    <a class="layui-btn layui-btn-xs " lay-event="edit" id="edit">编辑</a>
    <a class="layui-btn layui-bg-orange layui-btn-xs" lay-event="feedback" id="feedback">反馈</a>
    <a class="layui-btn layui-bg-blue  layui-btn-xs" lay-event="consulte" id="consulte">申请咨询</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" id="del">删除</a>
    {{# } }}
</script>
<script type="text/html" id="barDemo1">
    {{#if( d.file2 != null && d.file1 != "" ){ }}
    <a class="layui-btn layui-bg-blue layui-btn-xs"  href="/hbats{{ d.file1 }} " target="_blank">下载</a>
    {{# } }}
</script>
<script type="text/html" id="barDemo2">
    {{#if( d.file2 != null && d.file2 != "" ){ }}
    <a class="layui-btn layui-bg-blue layui-btn-xs" href="/hbats{{ d.file2 }} " target="_blank">下载</a>
    {{# } }}
</script>
<script type="text/html" id="barDemo3">
{{#if( d.file3 != null && d.file3 != "" ){ }}
    <a class="layui-btn layui-bg-blue layui-btn-xs"  href="/hbats{{ d.file3 }} " target="_blank">下载</a>
{{# } }}
</script>
<script type="text/html" id="barDemo4">
    {{#if( d.resultFile != null && d.resultFile != "" ){ }}
    <a class="layui-btn layui-bg-blue layui-btn-xs"  href="/hbats{{ d.resultFile }} " target="_blank">下载</a>
    {{# } }}
</script>
<script>
    //方案类型
    var schemeType=3;
    /**
     *时间转换格式
     * @param str
     * @returns
     */
    function getMyDate(str){
        var oDate = new Date(str),
            oYear = oDate.getFullYear(),
            oMonth = oDate.getMonth()+1,
            oDay = oDate.getDate(),
            oTime = oYear +"-"+ getzf(oMonth) +"-"+ getzf(oDay);//最后拼接时间
        return oTime;
    };

    //补0操作
    function getzf(num){
        if(parseInt(num) < 10){
            num = '0'+num;
        }
        return num;
    }

    var laydate =null;
    var table2 = null;
    layui.use('table', function () {
        var table = layui.table;
        sort=1;//默认为只看自己
        table2 = table.render({
            elem: '#test'
            , url: getRootPath() + "atsSchemeAction/selectAll"
            , where: {schemeType: schemeType,remark:loginObj.user.filId,lookAtAllOrYourself:1}
            , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            , defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                , layEvent: 'LAYTABLE_TIPS'
                , icon: 'layui-icon-tips'
            }]
            , title: '方案列表'
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {
                    field: 'schemeId',
                    width: 80,
                    title: '序号',
                    templet: '<div><a class="layui-table-link">{{d.LAY_TABLE_INDEX+1}}</a></div>'
                }
                , {field: 'schemeName', title: '方案名称', width: 120, sort: true}
                , {field: 'year', title: '方案年份', width: 120, sort: true}
                , {field: 'month', title: '方案月份', width: 120, sort: true}
                , {field: 'file1', title: '附件一', width: 80, toolbar: '#barDemo1'}
                , {field: 'file2', title: '附件二', width: 80, toolbar: '#barDemo2'}
                , {field: 'file3', title: '附件三', width: 80, toolbar: '#barDemo3'}
                , {field: 'coachName', title: '教练员', width: 100, sort: true}
                , {field: 'resultExp', title: '实施情况', width: 100}
                , {field: 'resultEffect', title: '实施效果', width: 120}
                , {field: 'resultFile', title: '实施附件', width: 120,toolbar: '#barDemo4'}
                , {fixed: 'right', title: '操作', toolbar: '#barDemo'}
            ]]
            , page: true
        });



        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'add':
                    //iframe层
                    layer.open({
                        type: 2,
                        title: '方案维护页面',//标题
                        shadeClose: true,
                        shade: 0.3,//背景阴影
                        area: ['700px', '500px'],//大小
                        //参数为区分方案类型
                        content: 'AstSchemeAddOrUpdate.html?schemeType=' + schemeType, //iframe的url
                        end: function () {

                        }
                    });
                    break;
                case 'delMany':
                    var data = checkStatus.data;
                    var ids = "";
                    for (var i = 0; i < data.length; i++) {
                        ids += data[i].schemeId + ",";
                    }
                    ids = ids.slice(0, -1);
                    console.info(ids);
                    var url = getRootPath() + "atsSchemeAction/delete";
                    var datas = {schemeIds: ids};
                    $.post(url, datas, function (objs) {
                        layer.msg(objs.msg, {
                            icon: 6,
                            time: 500
                        }, function () {
                            window.location.reload();
                        });
                    }, "json");
                    break;
                case 'findByKey':
                    var schemeName=$("#schemeName").val();
                    var stime=$("#stime").val();
                    var etime=$("#etime").val();
                    table2.reload({
                        where: {
                            schemeType: schemeType,
                            schemeName: $("#schemeName").val(),
                            stime: $("#stime").val(),
                            etime: $("#etime").val(),
                            lookAtAllOrYourself:getLook()
                        },
                        page: {
                            curr: 1
                        }
                    });
                    rederTime();
                    //显示搜索的关键字
                    $("#schemeName").val(schemeName);
                    $("#stime").val(stime);
                    $("#etime").val(etime);
                    break;

                case 'findAllScheme':
                    table2.reload({
                        where: {
                            schemeType: schemeType,
                            remark: loginObj.manager.filId,
                            lookAtAllOrYourself:"0"
                        },
                        page: {
                            curr: 1
                        }
                    });
                    rederTime();

                    break;
                case 'onlyLookSelf':
                    table2.reload({
                        where: {
                            schemeType: schemeType,
                            remark: loginObj.manager.filId,
                            lookAtAllOrYourself:"1"
                        },
                        page: {
                            curr: 1
                        }
                    });
                    rederTime();
                    break;
                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            }
        });
        var data;

        //监听行工具事件
        table.on('tool(test)', function (obj) {

            data = obj.data;
            //删除方案
            if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    obj.del();
                    layer.close(index);
                    var url = getRootPath() + "atsSchemeAction/delete";
                    var datas = {schemeId: data.schemeId};
                    $.post(url, datas, function (obj) {
                        layer.msg(obj.msg, {
                            icon: 6,
                            time: 500
                        }, function () {
                            window.location.reload();
                        });
                    }, "json");
                });
                //编辑方案
            } else if (obj.event === 'edit') {
                //iframe层
                layer.open({
                    type: 2,
                    title: '方案维护页面',//标题
                    shadeClose: true,
                    shade: 0.3,//背景阴影
                    area: ['700px', '500px'],//大小
                    content: 'AstSchemeAddOrUpdate.html?schemeId=' + data.schemeId+'&remark='+1, //iframe的url
                    end: function () {
                        //table2.reload("test");//渲染
                    }
                });
                //查看方案
            } else if (obj.event === "look") {
                var url3 = getRootPath() + "atsSchemeAction/addExp";
                console.info(data.schemeId);
                console.info(getFormatDate());
                var data3 = {schemeId: data.schemeId, isRead: 1, readTime: getFormatDate()};

                $.post(url3, data3, function (obj3) {
                    if (obj3.num === 1) {
                        console.info("已阅读" + obj3.msg);
                    }

                });
                //iframe层
                layer.open({
                    type: 2,
                    title: '查看方案',//标题
                    shadeClose: true,
                    shade: 0.3,//背景阴影
                    area: ['900px', '600px'],//大小
                    content: 'AtsSchemeLook.html?schemeId=' + data.schemeId, //iframe的url
                    end: function () {
                        //table2.reload();//渲染

                    }

                });

            } else if (obj.event === "consulte") {
                //iframe层
                layer.open({
                    type: 2,
                    title: '申请咨询专家',//标题
                    shadeClose: true,
                    shade: 0.3,//背景阴影
                    area: ['600px', '350px'],//大小
                    content: 'AtsSchemeConsulte.html?schemeId=' + data.schemeId+'&schemeName='+data.schemeName, //iframe的url
                    end: function () {
                        //table2.reload("test");//渲染
                    }
                });
                //教练员反馈页面
            }else if(obj.event==="feedback"){
                //iframe层
                layer.open({
                    type: 2,
                    title: '方案反馈页面',//标题
                    shadeClose: true,
                    shade: 0.3,//背景阴影
                    area: ['700px', '450px'],//大小
                    //参数为区分方案类型
                    content: 'AtsSchemeExpertAddOrUpdate.html?schemeId='+data.schemeId+'&schemeName='+data.schemeName+'&schemeType=' + schemeType, //iframe的url
                    end: function () {

                    }
                });
            }else if(obj.event==="audit"){
                //iframe层
                layer.open({
                    type: 2,
                    title: '方案审核页面',//标题
                    shadeClose: true,
                    shade: 0.3,//背景阴影
                    area: ['700px', '600px'],//大小
                    //参数为区分方案类型
                    content: 'AtsSchemeAudit.html?schemeId='+data.schemeId+'&schemeType=' + schemeType, //iframe的url
                    end: function () {

                    }
                });
            }else if(obj.event==="reply"){
                //iframe层
                layer.open({
                    type: 2,
                    title: '专家回复页面',//标题
                    shadeClose: true,
                    shade: 0.3,//背景阴影
                    area: ['700px', '500px'],//大小
                    //参数为区分方案类型
                    content: 'AtsSchemeReply.html?schemeId='+data.schemeId+'&schemeType=' + schemeType, //iframe的url
                    end: function () {

                    }
                });
            }
        });




        //刷新时间
        layui.use('laydate', function () {
            laydate = layui.laydate;
            //开始时间、结束时间
            laydate.render({
                elem: '#stime',
                trigger: 'click'
            });

            laydate.render({
                elem: '#etime',
                trigger: 'click'
            });
        });


        /**
         * 刷新时间控件
         */
        function rederTime() {
            laydate.render({
                elem: '#stime',
                trigger: 'click'
            });

            laydate.render({
                elem: '#etime',
                trigger: 'click'
            });
        }

        //js获取当前时间
        function getFormatDate() {
            var nowDate = new Date();
            var year = nowDate.getFullYear();
            var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1) : nowDate.getMonth() + 1;
            var date = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate();
            var hour = nowDate.getHours() < 10 ? "0" + nowDate.getHours() : nowDate.getHours();
            var minute = nowDate.getMinutes() < 10 ? "0" + nowDate.getMinutes() : nowDate.getMinutes();
            var second = nowDate.getSeconds() < 10 ? "0" + nowDate.getSeconds() : nowDate.getSeconds();
            return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
        }

        /**
         * 获取看所有还是看自己
         */
        function getLook(){
            $.ajax({
                type: "POST",
                url: getRootPath() + "atsSchemeAction/getLook",
                data: null,
                xhrFields: {withCredentials: true},
                success: function(obj){
                    return obj;
                }
            });
        }
    });


</script>
</body>
</html>